<%@ page import="org.json.simple.*"%> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*" 
	import = "java.util.*"%>
<%
	request.setCharacterEncoding("UTF-8");

	int id_a = Integer.parseInt(request.getParameter("aid"));	
	String id_u = (String)session.getAttribute("logID");
	String bname = request.getParameter("bname");	
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	Connection con = null;
	String sql = null;
	int result;
	
	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		
		sql = "insert into BOOKMARK(bid, bname, btime, id_u, id_a)"
			  +"values(bookmarkSequence.nextval,?,sysdate,?,?)";
		
		PreparedStatement pstmt = con.prepareStatement(sql);

		
		
		pstmt.setString(1,bname);
	
		pstmt.setString(2, id_u);
		pstmt.setInt(3, id_a);
		pstmt.executeUpdate();
	
		con.commit();
		
		pstmt.close();
		con.close();
		
		JSONObject saved = new JSONObject();
		saved.put("result", "true");
		out.print(saved);
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
		JSONObject saved = new JSONObject();
		saved.put("result", "false");
		out.print(saved);
	}
			
%>